package com.newcapec.servlet;

import com.newcapec.bean.ColumnEntity;
import com.newcapec.bean.UserEntity;
import com.newcapec.dao.ColumnDao;
import com.newcapec.dao.SysUserDao;
import com.newcapec.dao.impl.ColumnDaoImpl;
import com.newcapec.dao.impl.SysUserDaoImpl;
import com.newcapec.service.ColumnService;
import com.newcapec.service.impl.ColumnServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Description:添加用户
 * @Author:yangshupeng
 * @Date: 2022/3/17 21:19
 * @Version:1.0
 */
@WebServlet("/addChannel")
public class AddColumnServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        /*req.setCharacterEncoding("utf-8");
        resp.setCharacterEncoding("utf-8");*/

        String columnName = req.getParameter("columnName");
        String sort = req.getParameter("sort");
        if (columnName != null && sort != null){
            ColumnEntity columnEntity = new ColumnEntity(columnName,Integer.parseInt(sort));
            ColumnService columnService = new ColumnServiceImpl();
            if (columnService.addColumn(columnEntity)){
                resp.sendRedirect("ColumnManagement.html");
            }
        }else {
            resp.getWriter().write("no");
        }


    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req,resp);
    }
}
